package com.ebelter.btcomlib.models.db.products.seneo;

import android.text.TextUtils;

import com.ebelter.btcomlib.models.db.AppDatabase;
import com.ebelter.btcomlib.utils.NumUtils;
import com.raizlabs.android.dbflow.annotation.Column;
import com.raizlabs.android.dbflow.annotation.PrimaryKey;
import com.raizlabs.android.dbflow.annotation.Table;
import com.raizlabs.android.dbflow.structure.BaseModel;

import java.util.Calendar;


//Seneo用户信息列表
@Table(database = AppDatabase.class)
public class SeneoUserinfos extends BaseModel {
    @PrimaryKey(autoincrement = true)//ID自增
    public long id;

    @Column
    public long host_id;

    @Column
    public long user_id;

    @Column
    public boolean isHost;

    @Column
    public String nickName;//昵称

    @Column
    public int height=-1;

    @Column
    public int sex=0;//0男1女

    @Column
    public int impedance;//阻抗

    @Column
    public int athlete=0;//0普通 1运动员

    @Column
    public String birthday;//生日 格式永远是1901-06-13

    @Column
    public String email;//邮箱

    @Column
    public float currentWeight;//当前体重

    @Column
    public float targetWeight;//目标体重


    public int getAge(){
        int year = getBirthdayIntValue(birthday,0,1991);
        int age = getAgeByBirthday(year);
        return age;
    }

    public static int getBirthdayIntValue(String string,int index,int defaultValue){
        if (TextUtils.isEmpty(string)){
            return defaultValue;
        }
        String[] args = string.split("-");
        if (args.length!=3){
            return defaultValue;
        }
        return NumUtils.string2Int(args[index],defaultValue);
    }

    public static int getAgeByBirthday(int year){
        Calendar calendar = Calendar.getInstance();
        return calendar.get(Calendar.YEAR)-year;
    }


    @Override
    public String toString() {
        return "SeneoUserinfos{" +
                "id=" + id +
                ", host_id=" + host_id +
                ", user_id=" + user_id +
                ", isHost=" + isHost +
                ", height=" + height +
                ", sex=" + sex +
                ", athlete=" + athlete +
                ", birthday='" + birthday + '\'' +
                ", email='" + email + '\'' +
                ", currentWeight=" + currentWeight +
                ", targetWeight=" + targetWeight +
                '}';
    }
}
